﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SuperFox
{
    public class ComboBoxExtension : ComboBox
    {
        public static readonly DependencyProperty RequiredProperty =
         DependencyProperty.Register("Required", typeof(bool), typeof(ComboBoxExtension),
               new PropertyMetadata(false, new PropertyChangedCallback(RequiredPropertyChanged)));

        public bool Required
        {
            get { return (bool)GetValue(RequiredProperty); }
            set { SetValue(RequiredProperty, value); }
        }

        private static void RequiredPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                (d as ComboBoxExtension).Background = App.Current.Resources["REQUIREDFIELDBACKGROUND"] as SolidColorBrush;
            }
        }


        public bool Validate()
        {
            if (Required && (this.SelectedItem == null) && this.Visibility == System.Windows.Visibility.Visible)
            {
                // style it acordingly 

                this.Style = App.Current.Resources["RequiredFieldCombo"] as Style;
                return false;
            }
            else
            {
                this.Style = null;
                return true;
            }
        } 
    }
}
